<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page language="java" import="java.io.*"%>
<%@page import="org.apache.commons.fileupload.*"%>
<%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>


<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";

%>
<%
	String openpath = null;
	String filename = request.getParameter("filename");
	String fileName = new String(filename.getBytes("ISO-8859-1"),
			"gb2312");
	String agens=request.getHeader("User-Agent") ;
	System.out.println("agens:"+agens);
	//openpath=this.getServletContext().getRealPath("/")+"templateFile\\";
	InputStream ins = null; //输入流初始化
	ins = new FileInputStream(fileName);
	System.out.println("打开文件路径：" + fileName);
	response.reset();
	response.setContentType("application/octet-stream");//设置客户端浏览器按所有格式的方式解析文档
	response.addHeader("Content-Disposition", "attachment; filename="
			+ fileName);//指定文件下载时的默认名，Content-Disposition参数是为了在客户端另存文件时提供一个建议的文件名
	int len = 0;
	try {
		byte[] buffer = new byte[1024];
		while ((len = ins.read(buffer, 0, 1024)) != -1)
		{
			response.getOutputStream().write(buffer, 0, len);
			out.clear();
			out=pageContext.pushBody();
		}
		
	} catch (Exception e) {
		e.printStackTrace();
	}
	ins.close();
%>
